<template>
  <div class="app-container">
    <div class="common-card damConfigForm">
      <div class="title mb-5">个人信息</div>
      <el-form ref="ruleForm" :model="form" :rules="rules" label-width="180px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="用户名" prop="accountNo">
              <el-input v-model="form.accountNo" readonly="true"  disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="昵称" prop="userName">
              <el-input v-model="form.userName" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="密码" prop="password">
              <el-input v-model="form.password" type = "password" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="form.sex" placeholder="请选择性别">
                <el-option label="男" value="男"></el-option>
                <el-option label="女" value="女"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="电话" prop="telPhone">
              <el-input v-model="form.telPhone" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="姓名" prop="nickName">
              <el-input v-model="form.nickName" @input="handleInput" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="年龄" prop="sex">
              <el-slider
                v-model="form.age"
                :min="18"
                :max="80"
                show-input
              ></el-slider>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="养殖面积" prop="telPhone">
              <el-input v-model="form.area" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="家庭地址" prop="nickName">
              <el-input v-model="form.address" @input="handleInput" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
        
        </el-row>
      </el-form>
      <div class="actionBox">
        <el-button type="success" @click="handleSubmit">保存</el-button>
      </div>
    </div>
  </div>
</template>


<script>
import { getInfo , updateUser} from "@/api/user";
import { getToken } from "@/utils/auth";
export default {
  data() {
    return {
      form: {},
    };
  },
  created() {
    this.getUserDetail();
  },
  methods: {
    handleSubmit() {
      this.$refs['ruleForm'].validate((valid) => {
        if (valid) {
            updateUser(this.form).then((res) => {
              if (res) {
                this.$message.success('编辑个人信息成功')
                this.handleCancel()
              } else {
                this.$message.error('编辑个人信息失败')
              }
            })
          
        }
      })
    },
    getUserDetail() {
      getInfo(getToken()).then((res) => {
        console.log(res);
        this.form = res.data;
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.damConfigForm {
  padding: 40px;
  .title {
    font-size: 20px;
    font-weight: 800;
  }
  .actionBox {
    display: flex;
    justify-content: center;
  }
}
.uploadArea {
  height: 200px;
  background-color: #ccc;
  cursor: pointer;
  border-radius: 4px;
  .iconBox {
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .previewImg {
    height: 100%;
    width: 100%;
  }
  .uploadBtn {
    display: none;
  }
  .icon {
    font-size: 80px;
    color: #888;
  }
}
</style>